﻿using Architecture.API.Application.Command.RoleCommand;
using Architecture.Domain;
using Architecture.Domain.Dto.RoleDto;
using Architecture.Domain.Service.RoleServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.RoleHandler
{
    public class RoleSerchCommandHandler : IRequestHandler<RoleSerchCommand, PagingRoleDto<Role>>
    {
        /// <summary>
        /// 角色服务接口
        /// </summary>
        private readonly IRoleService _roleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleService">角色服务接口</param>
        public RoleSerchCommandHandler(IRoleService roleService)
        {
            _roleService = roleService;
        }

        /// <summary>
        /// 查询全部角色信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回角色全部信息</returns>
        public async Task<PagingRoleDto<Role>> Handle(RoleSerchCommand request, CancellationToken cancellationToken)
        {
            return await _roleService.GetAllRole(request.PageIndex,request.PageSize,request.RoleName);
        }
    }
}
